<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>领料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style type="text/css">
        body {
            background-color: #ffffff;
        }
        /* 设置下拉框宽度 */
        /* input.layui-input.layui-unselect {width:400px} */
    </style>

</head>
<body>
<div class="layui-form layuimini-form">

    <div class="layui-form-item">
        <label class="layui-form-label required">申请编号</label>
        <div class="layui-input-block">
            <input style="width: 400px;" type="text" name="matId"  readonly="readonly" value="" class="layui-input" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">物料</label>
        <div class="layui-input-block" style="width: 400px;">
            <select id="maename" name="materialId" lay-verify="required" lay-reqtext="物料不能为空"  class="layui-input">
                <option value="">请选择</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">数量</label>
        <div class="layui-input-block" style="width: 400px;">
            <input type="text" name="number"  value="" class="layui-input" lay-verify="required" lay-reqtext="数量不能为空" placeholder="请输入领取数量">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认领取</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','laydate','layer'], function () {
        var laydate = layui.laydate;
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;

        //日期选择
        //常规用法
        laydate.render({
            elem: '#test1'
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.post('/materaldetailed/addmateraldetailed',data.field,function(data){
                var index = layer.alert(data.msg, {
                    title: '提示信息',
                    btn: ['继续领料', '关闭'],
                    yes: function (index, layero) {
                        layer.close(layer.index); //点击确定之后执行yes函数,关闭弹出层
                        location.reload();
                    },
                    btn2: function(index,layero){
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    }
                })
            },'json')
            return false;
        });

        /* 回显当前的物料信息 */
        $(function(){
            var url = location.search;
            var i = url.indexOf("=");
            var id = url.substring(i+1);
            $.ajax({
                url:'/material',
                type:"GET",
                dataType:"json",
                success:function(data){
                    var material = data.data;
                    for(var i = 0;i<material.length;i++){
                        var m = material[i]
                        var option;
                        option = $("<option>").val(m.maeId).html(m.maename);
                        $("#maename").append(option)
                    }
                    $("input[name='matId']").val(id)
                    /*重新渲染页面*/
                    form.render();
                }
            })
        })
    });

</script>
</body>
</html>